package com.lxf.education.service.impl;

import com.lxf.education.dao.StudentListMapper;
import com.lxf.education.pojo.StudentPojo;
import com.lxf.education.pojo.TeacherPojo;
import com.lxf.education.service.StudentListService;
import com.lxf.education.utils.ResultVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Luoxingfa on 2022/5/2 0002 19:45
 */
@Service
public class StudentListServiceImpl implements StudentListService {

    //映射mapper文件
    @Resource
    StudentListMapper studentListMapper;
    @Override
    public ResultVo getAll() {
        List<StudentPojo> pojoList = studentListMapper.getAll();
        return ResultVo.getSuccessVo("success",pojoList);
    }

    /**
     *
     * @param page
     * @param limit
     * @return
     */
    @Override
    public ResultVo getStudentList(Integer page, Integer limit) {
        try {
            //计算出初始页
            Integer start = (page-1)*limit;
            //查询数据
            List<StudentPojo> studentList = studentListMapper.getAllStudent(start,limit);
            //查询总条数
            int count = studentListMapper.finCount();
            ResultVo successVo = ResultVo.getSuccessVo("success",studentList);
            //将总条数设置进去
            successVo.setCount(count);
            return successVo;

        }catch (Exception e){
            e.printStackTrace();
            return ResultVo.getFailVo("fails");
        }
    }

    /**
     * @学生登录操作
     */
	@Override
	public List<TeacherPojo> findStu(String username, String password) {
		// TODO Auto-generated method stub
		return studentListMapper.findStu(username,password);
	}

	/**
	 * @根据学生姓名查询信息
	 */
	@Override
	public StudentPojo findStuByName(String name) {
		// TODO Auto-generated method stub
		return studentListMapper.findStuByname(name);
	}

	/**
	 * @根据id查询学生信息
	 */
	@Override
	public void selById(Integer id) {
		// TODO Auto-generated method stub
		studentListMapper.findStuById(id);
	}

	/**
	 * @根据id更正内容
	 */
	@Override
	public ResultVo updateStudent(Integer id, String value) {
		// TODO Auto-generated method stub
		StudentPojo student = new StudentPojo();
		student.setSid(id);
		student.setSname(value);
		student.setLoginName(value);
		student.setLoginPwd(value);
		student.setSclass(value);
		student.setScollege(value);
		student.setSmajor(value);
		
		studentListMapper.updateStu(student);
		return ResultVo.getSuccessVo("success");
	}

	/**
	 * @根据id删除信息
	 */
	@Override
	public ResultVo delStudentById(Integer id) {
		// TODO Auto-generated method stub
		studentListMapper.delStuById(id);
		return ResultVo.getSuccessVo("success");
	}

	/**
	 * @批量删除
	 */
	@Override
	public ResultVo delAllStu(Integer[] ids) {
		// TODO Auto-generated method stub
		studentListMapper.delAllStu(ids);
		return ResultVo.getSuccessVo("success");
	}
}
